//
//  CCQWriteCommentViewController.swift
//  photo
//
//  Created by zhongchuren on 2018/11/19.
//  Copyright © 2018年 sundusk. All rights reserved.
//

import UIKit

class CCQWriteCommentViewController: UIViewController,JNStarReteViewDelegate,UITextViewDelegate {
    
    let ScreenWidth  = UIScreen.main.bounds.width
    let ScreenHeight = UIScreen.main.bounds.height
    
    var starname:UILabel!
    var statrView:UIView!
    var lineView:UIView!
    var textView:UITextView!
    var moneyName:UILabel!
    var moneyNunber:UITextField!
    var starView: JNStarRateView!
    var dataArray:NSMutableArray!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor.white
        self.dataArray = NSMutableArray.init()
        let item=UIBarButtonItem(title: "发表", style: UIBarButtonItem.Style.plain, target: self, action:#selector(photoAction))
        self.navigationItem.rightBarButtonItem=item
       
        self.setupUI()
    }
    
    
    func setupUI(){
        starname = UILabel()
        self.view.addSubview(starname)
        starname.snp.makeConstraints { (make) in
            make.left.equalTo(self.view.snp.left).offset(10)
            make.width.equalTo(80)
            make.height.equalTo(15)
            make.top.equalTo(self.view.snp.top).offset(20)
        }
       
        starname.text = "商家评论"
        
        starname.textAlignment = NSTextAlignment.left
        starname.font = UIFont.systemFont(ofSize: 14)
        starname.textColor = UIColor.black
        
        lineView = UIView()
        self.view.addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.left.equalTo(self.view.snp.left).offset(10)
            make.right.equalTo(self.view.snp.right).offset(-10)
            make.height.equalTo(0.5)
            make.top.equalTo(starname.snp.bottom).offset(20)
            
        }
        lineView.backgroundColor = UIColor.init(red: 245/255.0, green: 245/255.0, blue: 245/255.0, alpha: 1)
        
        statrView = UIView()
        self.view.addSubview(statrView)
        statrView.snp.makeConstraints { (make) in
            make.left.equalTo(starname.snp.right).offset(15)
            make.centerY.equalTo(starname)
            make.width.equalTo(80)
            make.height.equalTo(20)
        }
        statrView.backgroundColor = UIColor.white
        
        
        
        // 星星评价
        starView = JNStarRateView.init(frame: CGRect(x:0,y:0,width: 80,height: 20), numberOfStars: 5, currentStarCount: 3.4)
        starView.isUserInteractionEnabled = true//不支持用户操作
        starView.delegate = self
        starView.followDuration = 0.1//滑动或点击后跟随到达时间
        starView.userPanEnabled = true //滑动
        starView.currentStarCount = 1 //当前显示的评星数
        starView.integerStar = false // 完整星星
        statrView.addSubview(starView)
        
        textView = UITextView()
        self.view.addSubview(textView)
        textView.snp.makeConstraints { (make) in
            make.left.equalTo(self.view.snp.left).offset(5)
            make.top.equalTo(lineView.snp.bottom).offset(5)
            make.right.equalTo(self.view.snp.right).offset(5)
            make.height.equalTo(150);
            
        }
        textView.backgroundColor = UIColor.white
        textView.text = "请输入要评论的内容"
        textView.textColor = UIColor.gray
        textView.delegate = self
        
        self.view.addSubview(picker)
        picker.snp.makeConstraints { (make) in
            make.left.right.equalTo(self.view)
            make.height.equalTo(ScreenWidth/5)
            make.top.equalTo(textView.snp.bottom).offset(10)
        }
        
       
        
     
        
        let backgroundView = UIView()
        self.view.addSubview(backgroundView)
        backgroundView.snp.makeConstraints { (make) in
            make.left.right.equalTo(self.view)
            make.height.equalTo(10)
            make.top.equalTo(picker.snp.bottom).offset(20)
            
        }
        backgroundView.backgroundColor = UIColor.init(red: 240/255.0, green: 242/255.0, blue: 245/255.0, alpha: 1)
        
        let moneyView = UIView()
        self.view.addSubview(moneyView)
        moneyView.snp.makeConstraints { (make) in
            make.top.equalTo(backgroundView.snp.bottom)
            make.left.right.equalTo(self.view)
            make.height.equalTo(50)
        }
        moneyView.backgroundColor = UIColor.white
        
        let bottonView = UIView()
        self.view.addSubview(bottonView)
        bottonView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalTo(self.view)
            make.top.equalTo(moneyView.snp.bottom)
        }
        bottonView.backgroundColor = UIColor.init(red: 240/255.0, green: 242/255.0, blue: 245/255.0, alpha: 1)
        
        
        
        moneyName = UILabel()
        bottonView.addSubview(moneyName)
        moneyName.snp.makeConstraints { (make) in
            make.left.equalTo(self.view.snp.left).offset(10)
            make.height.equalTo(15)
            make.centerY.equalTo(moneyView)
            make.width.equalTo(50)
        }
        moneyName.textColor = UIColor.black
        moneyName.text = "人均 "
        moneyName.font = UIFont.systemFont(ofSize: 14)
        moneyNunber = UITextField()
        moneyView.addSubview(moneyNunber)
        moneyNunber.snp.makeConstraints { (make) in
            make.left.equalTo(moneyName.snp.right).offset(5)
            make.right.equalTo(moneyView.snp.right).offset(5)
            make.centerY.equalTo(moneyView)
            make.top.bottom.equalTo(moneyView)
        }
        moneyNunber.font = UIFont.systemFont(ofSize: 14)
        moneyNunber.placeholder = "$ 请输入消费金额"
        moneyNunber.backgroundColor = UIColor.white
        
       
        
    }
    //MARK: - 星级协议代理
    func starRate(view starRateView: JNStarRateView, count: Float) {
        print(count)
    }
    
    
    
    
    
    
    @objc func photoAction(sender:UIButton){
        
       
        
        print(self.picker.tgphotos.count)
        
        
        
    }
    
    lazy var picker: TGPhotoPicker = TGPhotoPicker(self, frame: CGRect(x: 0, y: 50, width: UIScreen.main.bounds.width, height: ScreenWidth/5)) { _ in
        TGPhotoPickerConfig.shared.tg_type(.wechat)
            
            .tg_mainCellWH(self.ScreenWidth/5)
            .tg_mainColCount(5)
            .tg_colCount(5)
            .tg_maxImageCount(5)
        
        
        
        
    }
    

    
    // 文本框已经开始编辑
    func textViewDidBeginEditing(_ textView: UITextView) {
      
        if (self.textView.text == "请输入要评论的内容") {
            textView.text = ""
            textView.textColor = UIColor.black
        }
    }
    func textViewDidEndEditing(_ textView: UITextView) {
        
    }

  

}
